package cn.edu.bzu.ie.sf.mealsmisweb.controller;

import cn.edu.bzu.ie.sf.mealsmisweb.common.MyUtils;
import cn.edu.bzu.ie.sf.mealsmisweb.entity.ApkVersion;
import cn.edu.bzu.ie.sf.mealsmisweb.service.ApkVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 版本信息控制器类
 * @author  宋锋
 * @date 2019-03-22 14:48
 */
@RestController
@RequestMapping("/apkVersion")
public class ApkVersionController {
    @Autowired
    private ApkVersionService apkVersionService;     //业务实例


    //取得最新的版本信息数据的方法
    @RequestMapping(value = "/getTop1ApkVersion", method = RequestMethod.POST)
    public ApkVersion getTop1ApkVersion() {
        ApkVersion obj = apkVersionService.getTop1ApkVersion();
        return obj;
    }

    //更新最新的版本信息数据的方法
    @RequestMapping(value = "/updateTop1ApkVersion", method = RequestMethod.POST)
    public int updateTop1ApkVersion(HttpServletRequest request, HttpServletResponse response) {
        ApkVersion obj = new ApkVersion();
        String strId = request.getParameter("id");
        String versionCode = request.getParameter("versionCode");
        String versionName = request.getParameter("versionName");
        String editDt = MyUtils.getDateStrFromNow();

        obj.setId(Integer.parseInt(strId));
        obj.setVersionCode(Integer.parseInt(versionCode));
        obj.setVersionName(versionName);
        obj.setEditDt(editDt);

        int iReturn = apkVersionService.updateTop1ApkVersion(obj);
        return iReturn;
    }
}
